package com.cloud.bc.controller.pc;

import cn.hutool.core.util.StrUtil;
import com.cloud.bc.controller.BaseController;
import com.cloud.bc.model.domain.UserInfo;
import com.cloud.bc.model.entity.BcAuthentications;
import com.cloud.bc.model.entity.BcSingles;
import com.cloud.bc.service.BcAuthenticationsService;
import com.cloud.bc.service.BcSinglesService;
import com.cloud.bc.service.BcUsersService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//PC诚信认证
@Controller
@AllArgsConstructor
@RequestMapping("center/auth")
public class PcCenterAuthController extends BaseController {
    private final BcUsersService bcUsersService;
    private final BcSinglesService bcSinglesService;
    private final BcAuthenticationsService bcAuthenticationsService;

    /**
     * 诚信认证
     */
    @GetMapping("")
    public ModelAndView index(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = baseView(request, "诚信认证-用户中心", "pc/center/auth/index");
        view.addObject("bodyCss", "page_manage page_manage_auth");
        UserInfo userInfo = bcUsersService.getUserInfo(request);
        BcSingles bcSingles = bcSinglesService.selectOne(new BcSingles().setUserId(userInfo.getId()));
        view.addObject("singles", bcSingles);
        return view;
    }

    @GetMapping("identity")
    public ModelAndView identity(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = baseView(request, "身份认证", "pc/center/auth/identity");
        UserInfo userInfo = bcUsersService.getUserInfo(request);
        BcAuthentications bcAuthentications = bcAuthenticationsService.selectOne(new BcAuthentications().setUserId(userInfo.getId()));
        if (StrUtil.isEmpty(bcAuthentications.getIdCardPositivePhoto())) {
            //如果是空，添加默认图片
            bcAuthentications.setIdCardPositivePhoto("/m/img/page_auth_id_card_positive_photo.svg");
        }
        if (StrUtil.isEmpty(bcAuthentications.getIdCardBackPhoto())) {
            bcAuthentications.setIdCardBackPhoto("/m/img/page_auth_id_card_back_photo.svg");
        }
        view.addObject("auth", bcAuthentications);
        view.addObject("bodyCss", "page_manage page_manage_auth_public page_manage_auth_identity");
        return view;
    }

    @GetMapping("education")
    public ModelAndView education(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = baseView(request, "身份认证", "pc/center/auth/education");
        UserInfo userInfo = bcUsersService.getUserInfo(request);
        BcAuthentications bcAuthentications = bcAuthenticationsService.selectOne(new BcAuthentications().setUserId(userInfo.getId()));
        if (StrUtil.isEmpty(bcAuthentications.getEducationPic())) {
            //如果是空，添加默认图片
            bcAuthentications.setEducationPic("/m/img/page_auth_education_pic.svg");
        }
        view.addObject("auth", bcAuthentications);
        view.addObject("bodyCss", "page_manage page_manage_auth_public page_manage_auth_education");
        return view;
    }

    @GetMapping("work")
    public ModelAndView work(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = baseView(request, "工作认证", "pc/center/auth/work");
        UserInfo userInfo = bcUsersService.getUserInfo(request);
        BcAuthentications bcAuthentications = bcAuthenticationsService.selectOne(new BcAuthentications().setUserId(userInfo.getId()));
        if (StrUtil.isEmpty(bcAuthentications.getWorkPic())) {
            //如果是空，添加默认图片
            bcAuthentications.setWorkPic("/m/img/page_auth_work_pic.svg");
        }
        view.addObject("auth", bcAuthentications);
        view.addObject("bodyCss", "page_manage page_manage_auth_public page_manage_auth_work");
        return view;
    }

    @GetMapping("hause")
    public ModelAndView hause(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = baseView(request, "房产认证", "pc/center/auth/hause");
        UserInfo userInfo = bcUsersService.getUserInfo(request);
        BcAuthentications bcAuthentications = bcAuthenticationsService.selectOne(new BcAuthentications().setUserId(userInfo.getId()));
        if (StrUtil.isEmpty(bcAuthentications.getHausePic())) {
            //如果是空，添加默认图片
            bcAuthentications.setHausePic("/m/img/page_auth_hause_pic.svg");
        }
        view.addObject("auth", bcAuthentications);
        view.addObject("bodyCss", "page_manage page_manage_auth_public page_manage_auth_hause");
        return view;
    }

    @GetMapping("car")
    public ModelAndView car(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = baseView(request, "汽车认证", "pc/center/auth/car");
        UserInfo userInfo = bcUsersService.getUserInfo(request);
        BcAuthentications bcAuthentications = bcAuthenticationsService.selectOne(new BcAuthentications().setUserId(userInfo.getId()));
        if (StrUtil.isEmpty(bcAuthentications.getCarPic())) {
            //如果是空，添加默认图片
            bcAuthentications.setCarPic("/m/img/page_auth_car_pic.svg");
        }
        view.addObject("auth", bcAuthentications);
        view.addObject("bodyCss", "page_manage page_manage_auth_public page_manage_auth_car");
        return view;
    }
}
